# $Id: PKGBUILD 73275 2012-07-05 09:07:47Z spupykin $
# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Maintainer: Ondrej Jirman <megous@megous.com>

pkgname=mingw32-runtime
pkgver=3.20
pkgrel=4
arch=('any')
pkgdesc="mingw32 run-time library"
makedepends=('mingw32-w32api' 'mingw32-gcc')
options=(!strip)
license=(LGPL)
url="http://www.mingw.org/"
source=(http://downloads.sourceforge.net/mingw/mingwrt-$pkgver-mingw32-src.tar.gz)
md5sums=('26c0886cc60729b94956cc6d81cd076c')

build()
{
  cd $srcdir/mingwrt-$pkgver-mingw32

  sed -i "s%\r%%g" `find . -type f`
  sed -i -e "s%^W32API_INCLUDE=.*%W32API_INCLUDE=-I/usr/i486-mingw32/include%" `find -type f -name 'configure'`

  export CFLAGS="-mms-bitfields"

  ./configure \
    --prefix=/usr/i486-mingw32 \
    --target=i486-mingw32 \
    --host=i486-mingw32 \
    --build=$CHOST

  # ugly fix
  local _mgccver=`pacman -Q mingw32-gcc | cut -f2 -d\  | cut -f1 -d-`
  sed -i "s|# include_next <float.h>|# include </usr/lib/gcc/i486-mingw32/${_mgccver}/include/float.h>|" include/float.h

  make
  mkdir -p $pkgdir/usr/i486-mingw32/bin
  make install prefix=$pkgdir/usr/i486-mingw32

  cd $pkgdir
  rm -rf usr/i486-mingw32/{doc,man}
  find . -name '*.a' | xargs -rtl1 i486-mingw32-strip -g
}
